package com.huike.web.controller.clues.aop;

import com.huike.clues.service.ITbClueService;
import com.huike.common.constant.Constants;
import com.huike.common.core.redis.RedisCache;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class TbClueAop {

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private ITbClueService tbClueService;

//    @Pointcut("execution(* com.huike.*.service.ITbClueService.)")
//    public void point(){};

    @Around("execution(* com.huike.*.service.ITbClueService.deleteTbClu*(..))")
    public Object aroundDeleteClue(ProceedingJoinPoint pjp) throws Throwable {
        redisCache.deleteObject(Constants.CLUE_PHONE_KEY);
        redisCache.deleteObject(Constants.CLUE_ID_KEY);
        Object proceed = pjp.proceed();
        tbClueService.loadAllId();
        tbClueService.loadAllPhone();
        return proceed;
    }

    @Around("execution(* com.huike.*.service.ITbClueService.updateTbClue(..))")
    public Object aroundUpdate(ProceedingJoinPoint pjp) throws Throwable {
        redisCache.deleteObject(Constants.CLUE_PHONE_KEY);
        Object proceed = pjp.proceed();
        tbClueService.loadAllPhone();
        return proceed;
    }

    @Around("execution(* com.huike.*.service.ITbClueService.addTbClue(..))")
    public Object aroundAdd(ProceedingJoinPoint pjp) throws Throwable {
        redisCache.deleteObject(Constants.CLUE_PHONE_KEY);
        redisCache.deleteObject(Constants.CLUE_ID_KEY);
        Object proceed = (int)pjp.proceed();
        tbClueService.loadAllPhone();
        tbClueService.loadAllId();
        return proceed;
    }
}
